/*
* $Id: InterfaceDb.h 343 2011-11-21 09:38:08Z volokaleks@yandex.ru $
*
* Copyright 2009-2011 by Volokitin Alexey
* All rights reserved
*
*/
#ifndef _INTERFACE_DB_H_
#define _INTERFACE_DB_H_

#include "Base.h"
#include "DatabaseNames.h"

interface IDatabase;
interface IResult;

struct CTableItem
{
	std::tstring m_strNameColumn;
	std::tstring m_strValueColumn;
};

typedef std::vector<std::vector<CTableItem> > MyTable;

interface IReader{
	virtual int ReadUTF(std::tstring& value) = 0;
	virtual int ReadInt(int& value) = 0;
	virtual int ReadBool(bool& value) = 0;
	virtual int ReadTime(time_t& value) = 0;
	virtual void WriteUTF(const std::tstring& value) = 0;
	virtual void WriteInt(__int32 value) = 0;
	virtual void WriteBool(bool value) = 0;
	virtual void WriteTime(__int64 value) = 0;
};

interface IOperation : public IBase{
	interface i_content : public IBase{
		virtual void Clear() = 0;
		virtual void Set(const std::vector<CTableItem>& content) = 0;
	};
	typedef std::vector<i_content*> Table;
	virtual void UpdateValue(IDatabase* pDatabase) = 0;
	virtual IResult* GetValue(IDatabase* pDatabase) = 0;
	virtual void SetValue(IDatabase* pDatabase) = 0;
	virtual void DeleteValue(IDatabase* pDatabase) = 0;
};

interface ITable : public IOperation{
	virtual std::vector<std::tstring> GetColumns() = 0;
	virtual std::tstring GetNameTable() = 0;
	virtual void CreateTable(IDatabase* pDatabase) = 0;
	interface i_content : public IOperation::i_content{
		virtual std::tstring WriteData(IReader* pReader) = 0;
	};
};

interface IDatabase : public IBase{
	virtual MyTable ExecRequest(const std::tstring& strSqlRequest) = 0;
	virtual bool IsExistTable(const std::tstring& strTableName) = 0;
	virtual void BeginTransaction(const std::tstring& strNameTransaction = _T("")) = 0;
	virtual void EndTransaction(const std::tstring& strNameTransaction = _T("")) = 0;
	virtual bool IsOpen() = 0;
	virtual void Open() = 0;
	virtual void Close() = 0;
	virtual std::tstring GetDatabaseName() = 0;
};

interface IResult : public IBase{
	virtual size_t GetSizeResult() = 0;
	virtual IOperation::i_content* operator [](int nPos) = 0;
	virtual void ClearResult() = 0;
};

#endif /*_INTERFACE_DB_H_*/